@echo off
setlocal

:: 设置 MinGW 环境
set PATH=E:\safeware\mingw64\bin;%PATH%

:: 设置Go环境
set CGO_ENABLED=1
set GOOS=windows
set GOARCH=amd64

:: 检查 GCC
where gcc >nul 2>nul
if %ERRORLEVEL% NEQ 0 (
    echo Error: GCC not found! Please install MinGW-w64
    echo You can download it from: https://www.mingw-w64.org/downloads/
    pause
    exit /b 1
)

:: 创建 bin 目录(如果不存在)
if not exist bin mkdir bin

:: 清理之前的构建
if exist bin\awakend.exe del bin\awakend.exe

:: 显示当前Go环境
echo Current Go environment:
go env GOPATH
go env GOROOT
go env CGO_ENABLED
go env GOOS
go env GOARCH
gcc --version

:: 下载依赖
echo Downloading dependencies...
go mod tidy
go clean -cache

:: 构建程序
echo Building program...
go build -v -o bin/awakend.exe cmd/main.go

if %ERRORLEVEL% EQU 0 (
    echo Build successful!
    echo Executable created: bin/awakend.exe
) else (
    echo Build failed with error code: %ERRORLEVEL%
    echo Please check the error messages above
)

pause